package com.goods.controller.business;

import com.goods.business.service.SupplierService;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.SupplierVO;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Api(tags = "业务模块-物资来源相关接口")
@RestController
@RequestMapping("/business/supplier")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;


    /*编辑物资来源前回显数据*/
    @ApiOperation(value = "编辑物资来源",notes = "编辑物资来源")
    @GetMapping("/edit/{id}")
    public ResponseBean<SupplierVO> edit(@PathVariable Integer id){
        SupplierVO supplierVO=supplierService.edit(id);
        return ResponseBean.success(supplierVO);
    }

    /*编辑物资来源更新数据*/
    @ApiOperation(value = "编辑物资来源进行更新",notes = "编辑物资来源更新数据保存")
    @PutMapping("/update/{id}")
    public ResponseBean update(@RequestBody SupplierVO supplierVO,
                               @PathVariable Integer id){
        Boolean isUpdate= supplierService.update(supplierVO,id);
        if (isUpdate){
            return ResponseBean.success("更新成功");
        }
        return ResponseBean.error("更新失败");
    }




    /*查询物资来源列表*/

    @ApiOperation(value = "物资来源",notes = "显示物资来源列表")
    @GetMapping("/findSupplierList")
    public ResponseBean<PageVO<SupplierVO>> findSupplierList(
            @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
            @RequestParam(value = "name",defaultValue = "") String name,
            @RequestParam(value = "address",defaultValue = "") String address,
            @RequestParam(value = "contact",defaultValue = "") String contact,
            SupplierVO supplierVO){
        //获取物资来源列表
        PageVO<SupplierVO> findSupplierList=supplierService.findSupplierList(pageNum,pageSize,name,address,contact,supplierVO);
        return ResponseBean.success(findSupplierList);
    }
    /*
    * 添加物质来源*/

    @ApiOperation(value = "物资来源添加",notes = "显示物资来源添加")
    @PostMapping("/add")
    public ResponseBean add(@RequestBody SupplierVO supplierVO){
        Boolean isAdded=supplierService.add(supplierVO);
        if (isAdded){
            return  ResponseBean.success("添加成功");
        }
        return ResponseBean.error("添加失败");
    }

    /*删除物资来源*/
    @ApiOperation(value = "物资来源删除",notes = "删除物资来源")
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Integer id){
        Boolean isDeleted=supplierService.delete(id);
        if (isDeleted){
            return ResponseBean.success("删除成功");
        }
        return ResponseBean.error("删除失败");
    }


}
